package my.dao.impl;



import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import java.util.Map;

import my.dao.DaoException;
import my.dao.NoFoundRowException;
import my.dao.PreSQL;
import my.dao.RowMapper;
import my.dao.impl.rowmapper.AutoBeanRowMapperImpl;
import my.dao.impl.rowmapper.BooleanRowMapperImpl;
import my.dao.impl.rowmapper.DateRowMapperImpl;
import my.dao.impl.rowmapper.DoubleRowMapperImpl;
import my.dao.impl.rowmapper.FloatRowMapperImpl;
import my.dao.impl.rowmapper.IntegerRowMapperImpl;
import my.dao.impl.rowmapper.LongRowMapperImpl;
import my.dao.impl.rowmapper.StringRowMapperImpl;


/**
 * 
 * @author 夏冬琦
 * @version 3.0
 *
 */
public class TransactionDaoImpl extends AbstractDao{
	
	
	
	private boolean transaction;//是否已开启事务
	
	public TransactionDaoImpl() throws DaoException{
		try {			
			conn.setAutoCommit(false);
			this.closed=false;
		} catch (SQLException e) {
			this.close();
			throw new DaoException("创建Dao对象失败！",e);
		}
	}
	
	public TransactionDaoImpl(DaoConfig cfg) throws DaoException{
		super(cfg);
		try {			
			conn.setAutoCommit(false);
			this.closed=false;
		} catch (SQLException e) {
			this.close();
			throw new DaoException("创建Dao对象失败！",e);
		}
	}
	
	private boolean isTransaction() {
		if(closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		return transaction;
	}
	
	
	public void beginTransaction() throws DaoException {
		if(closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		//容错处理
		if(this.isTransaction()){
			throw new DaoException("事务已经开启，不允许重复开启事务！");
		}
		transaction=true;			
		
		
	}


	
	public void commitTransaction() throws DaoException {
		
		if(closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许提交事务！");
		}
		try {
			conn.commit();
			this.transaction=false;
		} catch (SQLException e) {
			throw new DaoException("提交事务失败！",e);
		}
		
	}

	
	public void rollbackTransaction() throws DaoException {
		
		if(closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许回滚事务！");
		}
		try {
			conn.rollback();
			this.transaction=false;			
		} catch (SQLException e) {
			throw new DaoException("回滚事务失败！",e);
		}
		
	}

	
	public void close() throws DaoException {
		if(closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		if(this.isTransaction()){//如果事务未结束，则在关闭资源的过程中自动回滚事务
			this.rollbackTransaction();
			System.err.println("警告：事务未结束，事务已在关闭资源的过程中被回滚！");
		}
		
		this.baseClose();
		
	}

	
	public int update(String sql, Object... args) throws DaoException {
		
		if(closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行更新！");
		}
		try {
			
			return this.baseUpdate(sql, args);	
			
		} catch (SQLException e) {
			throw new DaoException("更新失败！",e);
		}
		
	}

	
	public ResultSet query(String sql, Object... args) throws DaoException {
		
		if(closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		try {
			return baseQuery(sql, args);
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}
	
	public Object[][] queryArrayArray(String sql, Object... args)
			throws DaoException {
		if(closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		
		try {		
			List<Object[]> list = this.baseQueryListOfArray(sql, args);
			return list.toArray(new Object[list.size()][]);
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}
	
	public List<Map<String,Object>> queryMapList(String sql, Object... args) throws DaoException {
		
		if(closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		try {
			
			return this.baseQueryListOfMap(sql, args);	
			
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}
	
	
	
	public List<Object[]> queryArrayList(String sql, Object... args)
			throws DaoException {
		if(closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		try {
			
			return this.baseQueryListOfArray(sql, args);	
			
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}

	
	public <T> List<T> queryList(RowMapper<T> mapper, String sql, Object... args)
			throws DaoException {
		
		if(closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		try {
			
			return this.baseQuery(mapper, sql, args);	
			
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}
	
	public <T> List<T> queryBeanList(Class<T> beanClass, String sql,
			Object... args) throws DaoException {
		if(this.closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		try {
			return baseQuery(new AutoBeanRowMapperImpl<T>(beanClass), sql, args);
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}
	
	public <T> Object[] queryBeanArray(Class<T> beanClass,String sql,Object... args) throws DaoException {
		
		if(this.closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		try {
			List<T> list = baseQuery(new AutoBeanRowMapperImpl<T>(beanClass), sql, args);
			return list.toArray();
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
		
	}
	
	public List<Integer> queryIntegerList(String sql, Object... args)
			throws DaoException {
		if(this.closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		try {
			return baseQuery(IntegerRowMapperImpl.getInstance(), sql, args);
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}

	public List<Long> queryLongList(String sql, Object... args)
			throws DaoException {
		if(this.closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		try {
			return baseQuery(LongRowMapperImpl.getInstance(), sql, args);
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}

	public List<Float> queryFloatList(String sql, Object... args)
			throws DaoException {
		if(this.closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		try {
			return baseQuery(FloatRowMapperImpl.getInstance(), sql, args);
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}

	public List<Double> queryDoubleList(String sql, Object... args)
			throws DaoException {
		if(this.closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		try {
			return baseQuery(DoubleRowMapperImpl.getInstance(), sql, args);
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}

	public List<Boolean> queryBooleanList(String sql, Object... args)
			throws DaoException {
		if(this.closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		try {
			return baseQuery(BooleanRowMapperImpl.getInstance(), sql, args);
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}

	public List<Date> queryDateList(String sql, Object... args)
			throws DaoException {
		if(this.closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		try {
			return baseQuery(DateRowMapperImpl.getInstance(), sql, args);
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}

	public List<String> queryStringList(String sql, Object... args)
			throws DaoException {
		if(this.closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		try {
			return baseQuery(StringRowMapperImpl.getInstance(), sql, args);
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}
	
	public Map<String, Object> queryUniqueMap(String sql, Object... args)
			throws DaoException {
		if(this.closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		try {		
			return this.baseQueryUniqueMap(sql, args);			
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}

	public Object[] queryUniqueArray(String sql, Object... args)
			throws DaoException {
		if(this.closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		try {		
			return this.baseQueryUniqueArray(sql, args);			
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}
	
	public <T> T queryUniqueObject(RowMapper<T> mapper, String sql,
			Object... args) throws DaoException {
		
		if(closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		
		try {
			return this.baseQueryUniqueObject(mapper, sql, args);			
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}
	public <T> T queryUniqueBean(Class<T> beanClass, String sql,
			Object... args) throws DaoException {
		if(closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		
		try {
			return this.baseQueryUniqueObject(new AutoBeanRowMapperImpl<T>(beanClass), sql, args);			
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}
	
	public Integer queryInteger(String sql, Object... args) throws NoFoundRowException, DaoException {
		if(closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		
		try {
			return this.baseQueryUniqueObject(IntegerRowMapperImpl.getInstance(), sql, args);			
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}

	public Long queryLong(String sql, Object... args) throws NoFoundRowException, DaoException {
		if(closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		
		try {
			return this.baseQueryUniqueObject(LongRowMapperImpl.getInstance(), sql, args);			
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}

	public Float queryFloat(String sql, Object... args) throws NoFoundRowException, DaoException {
		if(closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		
		try {
			return this.baseQueryUniqueObject(FloatRowMapperImpl.getInstance(), sql, args);			
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}

	public Double queryDouble(String sql, Object... args) throws NoFoundRowException, DaoException {
		if(closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		
		try {
			return this.baseQueryUniqueObject(DoubleRowMapperImpl.getInstance(), sql, args);			
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}

	public Boolean queryBoolean(String sql, Object... args) throws NoFoundRowException, DaoException {
		if(closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		
		try {
			return this.baseQueryUniqueObject(BooleanRowMapperImpl.getInstance(), sql, args);			
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}

	public Date queryDate(String sql, Object... args) throws NoFoundRowException, DaoException {
		if(closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		
		try {
			return this.baseQueryUniqueObject(DateRowMapperImpl.getInstance(), sql, args);			
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}

	public String queryString(String sql, Object... args) throws NoFoundRowException, DaoException {
		if(closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许执行查询！");
		}
		
		try {
			return this.baseQueryUniqueObject(StringRowMapperImpl.getInstance(), sql, args);			
		} catch (SQLException e) {
			throw new DaoException("查询失败！",e);
		}
	}

	
	public PreSQL preSQL(final String sql) throws DaoException{
		
		if(closed){
			throw new DaoException("本Dao对象已经关闭！");
		}
		
		if(!this.isTransaction()){
			throw new DaoException("事务尚未开启，不允许创建PreSQL对象！");
		}
		
		try {
			
			return new PreSQL(){
				
				private PreparedStatement pstmt=baseCreatePreparedStatement(sql);
				

				
				public int update(Object... args) throws DaoException {
					
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}
					
					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行更新！");
					}
					
					try {											
						return baseSetArgs4PreparedStatement(this.pstmt, args).executeUpdate();						
					} catch (SQLException e) {
						throw new DaoException("更新失败！",e);
					}
					
				}

				
				public ResultSet query(Object... args) throws DaoException {
					
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}
					
					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {						
						return baseQuery(baseSetArgs4PreparedStatement(this.pstmt, args));						
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
				}

				public List<Map<String, Object>> queryMapList(Object... args)
						throws DaoException {
					
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}

					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {						
						ResultSet rs=baseQuery(baseSetArgs4PreparedStatement(this.pstmt, args));											
						return baseMakeResultSetToListOfMap(rs);
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
				}


				public <T> List<T> queryList(RowMapper<T> mapper, Object... args)
						throws DaoException {
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}

					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {						
						ResultSet rs=baseQuery(baseSetArgs4PreparedStatement(this.pstmt, args));											
						return baseMakeResultSetToList(mapper, rs);
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
				}

				public Map<String, Object> queryUniqueMap(Object... args)
						throws DaoException {
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}
					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {
						ResultSet rs=baseQuery(baseSetArgs4PreparedStatement(pstmt, args));
						return baseMakeResultSetToUniqueMap(rs);
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
					
				}

				public Object[] queryUniqueArray(Object... args)
						throws DaoException {
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}
					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {
						ResultSet rs=baseQuery(baseSetArgs4PreparedStatement(pstmt, args));
						return baseMakeResultSetToUniqueArray(rs);
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
				}
				
				
				public <T> T queryUniqueObject(RowMapper<T> mapper,
						Object... args) throws DaoException {
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}

					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {						
						ResultSet rs=baseQuery(baseSetArgs4PreparedStatement(this.pstmt, args));											
						return baseMakeResultSetToUniqueObject(mapper, rs);
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
				}


				public <T> List<T> queryBeanList(Class<T> beanClass, Object... args)
						throws DaoException {
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}

					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {						
						ResultSet rs=baseQuery(baseSetArgs4PreparedStatement(this.pstmt, args));											
						return baseMakeResultSetToList(new AutoBeanRowMapperImpl<T>(beanClass), rs);
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
				}


				public <T> T queryUniqueBean(Class<T> beanClass,
						Object... args) throws DaoException {
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}

					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {						
						ResultSet rs=baseQuery(baseSetArgs4PreparedStatement(this.pstmt, args));											
						return baseMakeResultSetToUniqueObject(new AutoBeanRowMapperImpl<T>(beanClass), rs);
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
				}


				public Integer queryInteger(Object... args) throws DaoException {
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}

					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {						
						ResultSet rs=baseQuery(baseSetArgs4PreparedStatement(this.pstmt, args));											
						return baseMakeResultSetToUniqueObject(IntegerRowMapperImpl.getInstance(), rs);
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
				}


				public Long queryLong(Object... args) throws DaoException {
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}

					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {						
						ResultSet rs=baseQuery(baseSetArgs4PreparedStatement(this.pstmt, args));											
						return baseMakeResultSetToUniqueObject(LongRowMapperImpl.getInstance(), rs);
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
				}


				public Float queryFloat(Object... args) throws DaoException {
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}

					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {						
						ResultSet rs=baseQuery(baseSetArgs4PreparedStatement(this.pstmt, args));											
						return baseMakeResultSetToUniqueObject(FloatRowMapperImpl.getInstance(), rs);
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
				}


				public Double queryDouble(Object... args) throws DaoException {
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}

					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {						
						ResultSet rs=baseQuery(baseSetArgs4PreparedStatement(this.pstmt, args));											
						return baseMakeResultSetToUniqueObject(DoubleRowMapperImpl.getInstance(), rs);
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
				}


				public Boolean queryBoolean(Object... args) throws DaoException {
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}

					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {						
						ResultSet rs=baseQuery(baseSetArgs4PreparedStatement(this.pstmt, args));											
						return baseMakeResultSetToUniqueObject(BooleanRowMapperImpl.getInstance(), rs);
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
				}


				public Date queryDate(Object... args) throws DaoException {
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}

					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {						
						ResultSet rs=baseQuery(baseSetArgs4PreparedStatement(this.pstmt, args));											
						return baseMakeResultSetToUniqueObject(DateRowMapperImpl.getInstance(), rs);
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
				}


				public String queryString(Object... args) throws DaoException {
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}

					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {						
						ResultSet rs=baseQuery(baseSetArgs4PreparedStatement(this.pstmt, args));											
						return baseMakeResultSetToUniqueObject(StringRowMapperImpl.getInstance(), rs);
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
				}


				public List<Integer> queryIntegerList(Object... args)
						throws DaoException {
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}

					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {						
						ResultSet rs=baseQuery(baseSetArgs4PreparedStatement(this.pstmt, args));											
						return baseMakeResultSetToList(IntegerRowMapperImpl.getInstance(), rs);
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
				}


				public List<Long> queryLongList(Object... args)
						throws DaoException {
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}

					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {						
						ResultSet rs=baseQuery(baseSetArgs4PreparedStatement(this.pstmt, args));											
						return baseMakeResultSetToList(LongRowMapperImpl.getInstance(), rs);
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
				}


				public List<Float> queryFloatList(Object... args)
						throws DaoException {
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}

					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {						
						ResultSet rs=baseQuery(baseSetArgs4PreparedStatement(this.pstmt, args));											
						return baseMakeResultSetToList(FloatRowMapperImpl.getInstance(), rs);
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
				}


				public List<Double> queryDoubleList(Object... args)
						throws DaoException {
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}

					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {						
						ResultSet rs=baseQuery(baseSetArgs4PreparedStatement(this.pstmt, args));											
						return baseMakeResultSetToList(DoubleRowMapperImpl.getInstance(), rs);
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
				}


				public List<Boolean> queryBooleanList(Object... args)
						throws DaoException {
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}

					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {						
						ResultSet rs=baseQuery(baseSetArgs4PreparedStatement(this.pstmt, args));											
						return baseMakeResultSetToList(BooleanRowMapperImpl.getInstance(), rs);
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
				}


				public List<Date> queryDateList(Object... args)
						throws DaoException {
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}

					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {						
						ResultSet rs=baseQuery(baseSetArgs4PreparedStatement(this.pstmt, args));											
						return baseMakeResultSetToList(DateRowMapperImpl.getInstance(), rs);
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
				}


				public List<String> queryStringList(Object... args)
						throws DaoException {
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}

					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {						
						ResultSet rs=baseQuery(baseSetArgs4PreparedStatement(this.pstmt, args));											
						return baseMakeResultSetToList(StringRowMapperImpl.getInstance(), rs);
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
				}
				
				public List<Object[]> queryArrayList(Object... args)
						throws DaoException {
					if(closed){
						throw new DaoException("本Dao对象已经关闭！");
					}
					if(!isTransaction()){
						throw new DaoException("事务尚未开启，不允许执行查询！");
					}
					try {
						ResultSet rs=baseQuery(baseSetArgs4PreparedStatement(pstmt, args));
						return baseMakeResultSetToListOfArray(rs);
					} catch (SQLException e) {
						throw new DaoException("查询失败！",e);
					}
				}
				
				
			};
			
		} catch (SQLException e) {
			throw new DaoException(e);
		}
	}

}
